import unittest,requests
from ddt import ddt,data,unpack,file_data
from rk4.Toocl import A3mall

path = r'C:\Users\HP\Desktop\login.xlsx'
sheetname = "Sheet1"
dy = A3mall(path, sheetname)
print(dy.getDAta())

@ddt
class A3mall(unittest.TestCase):
    #登录 login
    token=None
    @unpack
    @data(*dy.getDAta())
    def test_01_login(self,username,password):
        url='http://10.59.9.14:7003/api/public/login'
        json={'username': username, 'password': password}
        login=requests.post(url=url,data=json)
        print(login.json())
        A3mall.token=login.json()['data']['token']
        print(A3mall.token)

    #加入购物车 add
    @file_data("gwc.json")
    @unpack
    def test_02_add(self,id,sku_id,num):
        url='http://10.59.9.14:7003/api/cart/add'
        headers={'auth-token':'Bearer '+A3mall.token}
        json={'id': id, 'sku_id': sku_id, 'num': num}
        add=requests.post(url=url,headers=headers,json=json)
        print(add.json())


if __name__ == '__main__':
    unittest.main()